package com.wx.gof.pattern.behavioral.memo;

import lombok.Data;

import java.util.Stack;

/**
 * @ClassName Notes
 * @Author wx
 * @Description 笔记
 * @Date 2018-12-14-21:37
 */
@Data
public class Notes {
    private String title;
    private String content;
    private String imgs;
    Stack<NotesCopy> notesCopyStack = new Stack<>();

    public
    Notes(String title, String content, String imgs) {
        this.title = title;
        this.content = content;
        this.imgs = imgs;
    }
    
    /**
     * @methodName: saveNotesCopy
     * @author: wx
     * @description: 保存
     * @param 
     * @date: 2018/12/14
     * @return: void
     */
    public void  saveNotesCopy(){
        notesCopyStack.add(new NotesCopy());
    }
    
    /**
     * @methodName: undo
     * @author: wx
     * @description: 撤销
     * @param
     * @date: 2018/12/14
     * @return: void
     */
    public void  undo(){
        NotesCopy notesCopy = notesCopyStack.pop();
        setTitle(notesCopy.getTitle());
        setContent(notesCopy.getContent());
        setImgs(notesCopy.getImgs());
    }


    @Override
    public String toString() {
        return "Notes{" + "title='" + title + '\'' + ", content='" + content + '\'' + ", imgs='" + imgs + '\'' + ", notesCopyStack=" + notesCopyStack + '}';
    }

    /**
     * @Author wx
     * @Description 笔记副本
     * @Date 2018-12-14
     */
   private  class NotesCopy {
        private String title;
        private String content;
        private String imgs;

        public NotesCopy() {
            this.title = Notes.this.title;
            this.content = Notes.this.content;
            this.imgs = Notes.this.imgs;
        }

        public String getTitle() {
            return title;
        }

        public String getContent() {
            return content;
        }

        public String getImgs() {
            return imgs;
        }
    }
}
